﻿// Copyright © Microsoft Corporation.  All Rights Reserved.
// This code released under the terms of the 
// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)

namespace Expression.Samples.PathListBoxUtils
{
	using System;
	using System.Windows;
	using System.Windows.Data;

	public class AdjustedOffsetToRadiusConverter : IValueConverter
	{
		public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			if (value == null || !(value is double))
			{
				throw new ArgumentException("Must be of type double.", "value");
			}

			double convertedParameter = 1;
			if (parameter != null && !double.TryParse(parameter.ToString(), out convertedParameter))
			{
				throw new ArgumentException("Must be of type double.", "parameter");
			}

			return (((1 - (double)value)) * convertedParameter);
		}

		public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			return DependencyProperty.UnsetValue;
		}
	}
}
